import matplotlib.pyplot as plt
import numpy as np
from process import utils


y1 = [15.85, 13.78, 13.13, 12.05, 10.16, 11.84, 12.68, 11.97, 10.25]
y2 = [24.23, 23.87, 23.56, 22.21, 22.42, 17.48, 15.03, 15.22, 15.76]
y3 = [15.94, 15.89, 15.14, 15.65, 15.73, 13.81, 11.61, 12.46, 13.07]
y4 = [16.29, 16.37, 16.41, 17.13, 18.47, 14.34, 10.69, 10.06, 9.82]


aRR_y1 = [[16.42, 16.16, 17.67, 14.91, 14.15, 18.43, 15.15, 17.43, 18.63, 13.95, 18.23, 14.35, 17.75, 14.83, 15.87, 16.71, 18.62, 13.96, 15.54, 17.04, 15.57, 17.01, 17.66, 14.92, 19.14, 13.44, 15.28, 17.3, 16.66, 15.92], [15.91, 16.83, 19.02, 13.72, 15.16, 17.58, 15.75, 16.99, 16.59, 16.15, 14.51, 18.23, 15.56, 17.18, 13.55, 19.19, 14.12, 18.62, 18.66, 14.08, 17.62, 15.12, 18.13, 14.61, 17.58, 15.16, 16.64, 16.1, 14.3, 18.44], [16.33, 16.49, 17.94, 14.88, 17.54, 15.28, 14.84, 17.98, 15.54, 17.28, 14.85, 17.97, 17.23, 15.59, 15.62, 17.2, 19.76, 13.06, 15.58, 17.24, 12.62, 20.2, 15.0, 17.82, 18.26, 14.56, 14.73, 18.09, 16.26, 16.56], [18.03, 16.23, 18.25, 16.01, 18.64, 15.62, 15.99, 18.27, 16.64, 17.62, 15.79, 18.47, 17.13, 17.13, 16.13, 18.13, 15.78, 18.48, 17.75, 16.51, 17.16, 17.1, 18.77, 15.49, 16.37, 17.89, 17.78, 16.48, 18.96, 15.3], [17.4, 19.54, 19.97, 16.97, 19.16, 17.78, 20.05, 16.89, 20.25, 16.69, 19.78, 17.16, 19.91, 17.03, 18.17, 18.77, 17.85, 19.09, 18.77, 18.17, 18.82, 18.12, 17.88, 19.06, 18.43, 18.51, 18.0, 18.94, 18.35, 18.59], [13.88, 14.8, 14.92, 13.76, 15.14, 13.54, 13.59, 15.09, 13.92, 14.76, 13.92, 14.76, 13.43, 15.25, 14.49, 14.19, 13.48, 15.2, 14.83, 13.85, 14.29, 14.39, 13.61, 15.07, 13.55, 15.13, 15.03, 13.65, 15.22, 13.46], [10.29, 11.09, 6.93, 14.45, 12.13, 9.25, 11.79, 9.59, 11.71, 9.67, 11.24, 10.14, 13.49, 7.89, 13.35, 8.03, 12.99, 8.39, 12.92, 8.46, 9.27, 12.11, 7.07, 14.31, 9.41, 11.97, 8.7, 12.68, 9.48, 11.9], [9.72, 10.4, 9.71, 10.41, 9.28, 10.84, 10.47, 9.65, 9.84, 10.28, 10.54, 9.58, 9.09, 11.03, 9.1, 11.02, 10.76, 9.36, 9.7, 10.42, 10.95, 9.17, 9.9, 10.22, 9.19, 10.93, 9.91, 10.21, 9.49, 10.63], [8.59, 11.05, 12.11, 7.53, 10.79, 8.85, 9.91, 9.73, 10.24, 9.4, 6.96, 12.68, 7.41, 12.23, 12.8, 6.84, 10.99, 8.65, 9.7, 9.94, 7.72, 11.92, 8.46, 11.18, 10.82, 8.82, 6.9, 12.74, 9.09, 10.55]]
aRR_y2 = [[24.98, 23.48, 24.19, 24.27, 23.79, 24.67, 24.91, 23.55, 23.46, 25.0, 24.6, 23.86, 24.2, 24.26, 23.93, 24.53, 23.25, 25.21, 23.37, 25.09, 24.16, 24.3, 24.82, 23.64, 24.59, 23.87, 25.02, 23.44, 23.74, 24.72], [22.51, 25.23, 21.74, 26.0, 25.82, 21.92, 25.81, 21.93, 22.94, 24.8, 20.57, 27.17, 20.73, 27.01, 23.39, 24.35, 26.43, 21.31, 27.52, 20.22, 27.04, 20.7, 25.97, 21.77, 20.41, 27.33, 20.44, 27.3, 21.17, 26.57], [23.45, 23.67, 24.78, 22.34, 22.9, 24.22, 23.6, 23.52, 22.95, 24.17, 23.02, 24.1, 22.26, 24.86, 23.88, 23.24, 22.43, 24.69, 23.67, 23.45, 21.64, 25.48, 24.31, 22.81, 22.29, 24.83, 23.17, 23.95, 23.27, 23.85], [21.79, 22.63, 22.33, 22.09, 23.17, 21.25, 21.96, 22.46, 22.53, 21.89, 22.68, 21.74, 22.4, 22.02, 21.63, 22.79, 22.46, 21.96, 22.44, 21.98, 22.54, 21.88, 22.53, 21.89, 22.7, 21.72, 22.69, 21.73, 22.25, 22.17], [21.71, 23.13, 19.62, 25.22, 25.01, 19.83, 21.98, 22.86, 19.85, 24.99, 25.13, 19.71, 23.52, 21.32, 19.49, 25.35, 21.72, 23.12, 25.09, 19.75, 20.72, 24.12, 22.66, 22.18, 21.38, 23.46, 20.68, 24.16, 22.69, 22.15], [15.82, 19.14, 20.68, 14.28, 19.09, 15.87, 18.97, 15.99, 15.0, 19.96, 14.78, 20.18, 18.05, 16.91, 18.37, 16.59, 21.11, 13.85, 20.68, 14.28, 18.43, 16.53, 21.07, 13.89, 15.98, 18.98, 13.49, 21.47, 20.84, 14.12], [17.67, 12.39, 13.6, 16.46, 12.4, 17.66, 15.44, 14.62, 13.5, 16.56, 12.39, 17.67, 14.38, 15.68, 16.93, 13.13, 12.62, 17.44, 16.27, 13.79, 16.39, 13.67, 15.14, 14.92, 17.26, 12.8, 13.93, 16.13, 13.31, 16.75], [15.57, 14.87, 17.45, 12.99, 18.07, 12.37, 13.72, 16.72, 17.65, 12.79, 17.02, 13.42, 12.28, 18.16, 15.05, 15.39, 18.78, 11.66, 15.26, 15.18, 16.79, 13.65, 12.9, 17.54, 12.27, 18.17, 16.91, 13.53, 17.51, 12.93], [16.73, 14.79, 16.23, 15.29, 15.16, 16.36, 16.39, 15.13, 16.19, 15.33, 15.44, 16.08, 16.05, 15.47, 15.9, 15.62, 16.05, 15.47, 15.1, 16.42, 15.77, 15.75, 16.4, 15.12, 15.16, 16.36, 15.69, 15.83, 14.92, 16.6]]
aRR_y3 = [[18.19, 13.69, 16.38, 15.5, 13.81, 18.07, 16.31, 15.57, 13.0, 18.88, 14.05, 17.83, 13.87, 18.01, 13.58, 18.3, 14.24, 17.64, 13.47, 18.41, 14.17, 17.71, 14.77, 17.11, 17.2, 14.68, 15.42, 16.46, 14.0, 17.88], [16.34, 15.44, 15.29, 16.49, 15.95, 15.83, 15.78, 16.0, 16.14, 15.64, 15.08, 16.7, 15.53, 16.25, 15.49, 16.29, 15.07, 16.71, 16.67, 15.11, 15.14, 16.64, 16.85, 14.93, 16.01, 15.77, 15.95, 15.83, 16.69, 15.09], [16.07, 14.21, 15.34, 14.94, 16.8, 13.48, 15.94, 14.34, 13.82, 16.46, 16.46, 13.82, 15.06, 15.22, 16.55, 13.73, 15.44, 14.84, 14.77, 15.51, 17.11, 13.17, 16.34, 13.94, 16.94, 13.34, 15.07, 15.21, 15.32, 14.96], [19.34, 11.96, 13.16, 18.14, 18.88, 12.42, 17.64, 13.66, 17.54, 13.76, 11.92, 19.38, 19.45, 11.85, 15.28, 16.02, 13.8, 17.5, 15.39, 15.91, 18.52, 12.78, 12.47, 18.83, 17.46, 13.84, 17.94, 13.36, 13.08, 18.22], [16.07, 15.39, 16.5, 14.96, 16.68, 14.78, 14.87, 16.59, 15.92, 15.54, 14.81, 16.65, 16.11, 15.35, 16.41, 15.05, 16.34, 15.12, 16.0, 15.46, 15.3, 16.16, 15.36, 16.1, 15.55, 15.91, 15.06, 16.4, 15.76, 15.7], [14.56, 13.06, 13.13, 14.49, 13.45, 14.17, 14.05, 13.57, 13.92, 13.7, 13.88, 13.74, 13.01, 14.61, 14.58, 13.04, 14.36, 13.26, 14.54, 13.08, 14.4, 13.22, 13.64, 13.98, 14.77, 12.85, 13.93, 13.69, 12.95, 14.67], [11.19, 12.03, 10.72, 12.5, 11.39, 11.83, 11.08, 12.14, 12.19, 11.03, 12.05, 11.17, 11.76, 11.46, 10.84, 12.38, 10.87, 12.35, 12.47, 10.75, 12.18, 11.04, 11.42, 11.8, 11.42, 11.8, 12.36, 10.86, 11.17, 12.05], [13.42, 11.5, 11.88, 13.04, 13.32, 11.6, 11.12, 13.8, 11.73, 13.19, 11.79, 13.13, 11.75, 13.17, 13.39, 11.53, 14.4, 10.52, 10.75, 14.17, 12.06, 12.86, 13.3, 11.62, 14.02, 10.9, 12.78, 12.14, 11.17, 13.75], [13.67, 12.47, 12.35, 13.79, 14.43, 11.71, 11.47, 14.67, 13.57, 12.57, 12.13, 14.01, 15.0, 11.14, 11.43, 14.71, 13.09, 13.05, 11.43, 14.71, 14.23, 11.91, 14.0, 12.14, 13.86, 12.28, 14.63, 11.51, 14.71, 11.43]]
aRR_y4 = [[16.07, 16.51, 15.94, 16.64, 14.18, 18.4, 16.21, 16.37, 19.22, 13.36, 16.42, 16.16, 13.77, 18.81, 14.41, 18.17, 17.35, 15.23, 17.94, 14.64, 15.83, 16.75, 17.89, 14.69, 14.92, 17.66, 17.43, 15.15, 16.35, 16.23], [18.56, 14.18, 16.68, 16.06, 15.88, 16.86, 15.37, 17.37, 18.86, 13.88, 15.43, 17.31, 19.2, 13.54, 18.62, 14.12, 16.42, 16.32, 14.84, 17.9, 18.13, 14.61, 16.13, 16.61, 15.36, 17.38, 18.22, 14.52, 15.29, 17.45], [20.07, 12.75, 13.88, 18.94, 17.24, 15.58, 20.18, 12.64, 15.56, 17.26, 13.49, 19.33, 16.48, 16.34, 13.38, 19.44, 16.53, 16.29, 20.38, 12.44, 16.25, 16.57, 18.31, 14.51, 18.82, 14.0, 14.26, 18.56, 16.06, 16.76], [19.11, 15.15, 15.58, 18.68, 18.77, 15.49, 15.33, 18.93, 17.39, 16.87, 17.71, 16.55, 17.01, 17.25, 15.92, 18.34, 17.67, 16.59, 15.55, 18.71, 18.13, 16.13, 16.8, 17.46, 17.39, 16.87, 19.04, 15.22, 18.78, 15.48], [18.21, 18.73, 17.06, 19.88, 18.75, 18.19, 17.97, 18.97, 16.72, 20.22, 18.37, 18.57, 16.69, 20.25, 17.63, 19.31, 20.42, 16.52, 18.54, 18.4, 19.96, 16.98, 18.8, 18.14, 17.86, 19.08, 18.06, 18.88, 16.56, 20.38], [14.95, 13.73, 14.11, 14.57, 13.63, 15.05, 14.44, 14.24, 15.32, 13.36, 14.03, 14.65, 14.31, 14.37, 14.7, 13.98, 13.8, 14.88, 14.89, 13.79, 13.73, 14.95, 14.66, 14.02, 15.12, 13.56, 14.54, 14.14, 13.59, 15.09], [12.83, 8.55, 14.44, 6.94, 9.69, 11.69, 11.76, 9.62, 13.53, 7.85, 8.61, 12.77, 13.89, 7.49, 13.67, 7.71, 13.13, 8.25, 14.36, 7.02, 10.2, 11.18, 11.96, 9.42, 6.92, 14.46, 10.29, 11.09, 13.55, 7.83], [10.98, 9.14, 10.79, 9.33, 10.98, 9.14, 10.81, 9.31, 9.08, 11.04, 10.53, 9.59, 9.1, 11.02, 10.44, 9.68, 9.36, 10.76, 10.34, 9.78, 10.35, 9.77, 9.41, 10.71, 9.95, 10.17, 10.64, 9.48, 10.63, 9.49], [7.24, 12.4, 7.53, 12.11, 9.63, 10.01, 12.42, 7.22, 7.75, 11.89, 8.63, 11.01, 9.01, 10.63, 12.21, 7.43, 10.53, 9.11, 11.2, 8.44, 8.64, 11.0, 9.84, 9.8, 9.39, 10.25, 9.61, 10.03, 12.55, 7.09]]

np.random.seed(4)
ar = np.array(y4)
aRR = [] # 存放结果
for i in range(ar.shape[0]):
    CONST = np.random.randint(1, 5)  # 浮动大小，就是[平均值-CONST, 平均值+CONST]之间的随机数
    tmp = []
    num = 30
    for j in range(num // 2):
        tmp.extend(utils.float_random(ar[i], ar[i] - CONST, ar[i] + CONST)) # 每次生成2个随机数
    aRR.append(tmp)
    # print(np.mean(np.array(tmp)))

np.savetxt("./csv/figure7c.csv", aRR, delimiter=",", fmt="%.2f")
print(aRR)


x = [0.4, 0.45, 0.5, 0.55, 0.6, 0.65, 0.7, 0.75, 0.8]

aRR_std1 = np.std(aRR_y1,axis=1)
aRR_std2 = np.std(aRR_y2,axis=1)
aRR_std3 = np.std(aRR_y3,axis=1)
aRR_std4 = np.std(aRR_y4,axis=1)

plt.plot(x, y1, 'bo-', markersize=8, label='LDC-COR')
plt.plot(x, y2, 'gv--', color='#00FF00', markersize=8, label='LDC-OR')
plt.plot(x, y3, 'r^--', markersize=8, label='LDC-ACOR')
plt.plot(x, y4, 'ks--', color='black', markersize=8, label='LDC-AOR')

plt.errorbar(x, y1, yerr=aRR_std1, fmt="bo-", color="blue", elinewidth=2, capsize=6,markersize=8)
plt.errorbar(x, y2, yerr=aRR_std2, fmt="v--", color='#00FF00', elinewidth=2, capsize=6,markersize=8)
plt.errorbar(x, y3, yerr=aRR_std3, fmt='r^--', elinewidth=2, capsize=4, markersize=8)
plt.errorbar(x, y4, yerr=aRR_std4, fmt='ks--', elinewidth=2, capsize=4, markersize=8)

plt.xticks([0.4, 0.5, 0.6, 0.7, 0.8], fontsize='14')
plt.yticks([10, 15, 20, 25], fontsize='14')
plt.grid(linewidth=0.4, color='#DFDFDF')
plt.xlabel('Link Quality', fontsize=18)
plt.ylabel('Energy Cost(W)', fontsize=18)
# plt.legend(['LDC-COR', 'LDC-OR', 'LDC-ACOR', 'LDC-AOR', 'AVERAGE'], loc='upper right', fontsize=14)
plt.legend(['LDC-COR', 'LDC-OR', 'LDC-ACOR', 'LDC-AOR'], loc='upper right', fontsize=14)

plt.tight_layout()
plt.savefig('./eps/figure7c.eps', dpi=600, format='eps')
plt.show()